<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link href="gadget.css" rel="stylesheet" type="text/css" />
		<script src="_js/tooltip.js" type="text/javascript"></script>
	</head>

	<script language="VBScript">
		Sub Window_Onload
			Dim tickerTimer, iconTimer, onlineTimer

			GetTicker
			tickerTimer = window.SetInterval("GetTicker", 60000)

			GetIcons
			iconTimer = window.SetInterval("GetIcons", 60000)

			GetOnline
			onlineTimer = window.SetInterval("GetOnline", 60000)
		End Sub

		Sub GetOnline
			Dim xmlParser, xlmNode, bSuccess, sOnline
			
			Set xmlParser = CreateObject("MSXML2.DOMDocument.6.0")
			xmlParser.Async = False
			bSuccess = xmlParser.Load("http://api.lunarstorm.se/api.ashx?gadget=true&type=xml&function=online")
			
			Set xlmNode = xmlParser.SelectSingleNode("online/item/onlinecount")
			If Not xlmNode Is Nothing then
				sOnline = xlmNode.Text
			Else
				sOnline = "..."
			End If
			Set xlmNode = Nothing
			
			onlineArea.InnerHTML = sOnline & " online"
		End Sub

		Sub GetIcons
			Dim sUsername
			Dim xmlParser, bSuccess, sOnline
			Dim gbNode, lmNode, fmNode, frNode, bcNode, gcNode, iCnt
			
			sUsername = "Webmaster"
			If System.Gadget.Settings.readString("Username") <> vbNullString Then
				sUsername = System.Gadget.Settings.readString("Username")
			End If
			
			Set xmlParser = CreateObject("MSXML2.DOMDocument.6.0")
			xmlParser.Async = False
			bSuccess = xmlParser.Load("http://api.lunarstorm.se/api.ashx?gadget=true&type=xml&function=notifications&user=" & sUsername)
			
			If bSuccess Then
				'If System.Gadget.Settings.readString("UpdateInfo") = "!" Then
					'Update userinfo for correct casing of Username etc
	
					'Once updated clear the update flag
					'System.Gadget.Settings.writeString("UpdateInfo", vbNullString)
				'End If
				
				infoArea.InnerHTML = sUsername
				
				Set gbNode = xmlParser.SelectSingleNode("notifications/item/guestbook")
				Set lmNode = xmlParser.SelectSingleNode("notifications/item/mail")
				Set fmNode = xmlParser.SelectSingleNode("notifications/item/diskus")
				Set frNode = xmlParser.SelectSingleNode("notifications/item/friends")
				Set bcNode = xmlParser.SelectSingleNode("notifications/item/blogcomments")
				Set gcNode = xmlParser.SelectSingleNode("notifications/item/gallerycomments")
				
				If Not gbNode Is Nothing Then
					iCnt = CInt(gbNode.Text)
					
					gbTooltip.value = sUsername & " har " & iCnt & " nya gästboks-inlägg."
					If iCnt > 0 Then
						gbIcon.src = "_gfx/icon/icon-guestbook-active.gif"
					Else
						gbIcon.src = "_gfx/icon/icon-guestbook.gif"
					End If
					'gbLink.href = "http://www.lunarstorm.se/" & sUsername
				End If
				
				If Not lmNode Is Nothing Then
					iCnt = CInt(lmNode.Text)
					
					lmTooltip.value = sUsername & " har " & iCnt & " nya mail."
					If iCnt > 0 Then
						lmIcon.src = "_gfx/icon/icon-lunarmail-active.gif"
					Else
						lmIcon.src = "_gfx/icon/icon-lunarmail.gif"
					End If
					'lmLink.href = "http://www.lunarstorm.se/" & sUsername
				End If
				
				If Not fmNode Is Nothing Then
					iCnt = CInt(fmNode.Text)
					
					fmTooltip.value = sUsername & " har " & iCnt & " nya forum notifieringar."
					If iCnt > 0 Then
						fmIcon.src = "_gfx/icon/icon-forum-active.gif"
					Else
						fmIcon.src = "_gfx/icon/icon-forum.gif"
					End If
					'fmLink.href = "http://www.lunarstorm.se/" & sUsername
				End If
				
				If Not frNode Is Nothing Then
					iCnt = CInt(fmNode.Text)
					
					frTooltip.value = sUsername & " har " & iCnt & " nya vänner förfrågningar."
					If iCnt > 0 Then
						frIcon.src = "_gfx/icon/icon-friends-active.gif"
					Else
						frIcon.src = "_gfx/icon/icon-friends.gif"
					End If
					'frLink.href = "http://www.lunarstorm.se/" & sUsername
				End If
				
				If Not bcNode Is Nothing And Not gcNode Is Nothing Then
					iCnt = (CInt(bcNode.Text) + CInt(gcNode.Text))
					
					cmTooltip.value = sUsername & " har " & iCnt & " nya kommentarer."
					If iCnt > 0 Then
						cmIcon.src = "_gfx/icon/icon-comment-active.gif"
					Else
						cmIcon.src = "_gfx/icon/icon-comment.gif"
					End If
					'cmLink.href = "http://www.lunarstorm.se/" & sUsername
				End If
				
				Set gbNode = Nothing
				Set lmNode = Nothing
				Set fmNode = Nothing
				Set frNode = Nothing
				Set bcNode = Nothing
				Set gcNode = Nothing
			End If
		End Sub

		Sub GetTicker
			Dim xmlHttp, xmlData, xmlParser
			Dim xlmNodes, xlmNode, xmlError
			Dim descNode, linkNode, publNode, titlNode
			Dim sText, sLink, sDate, sUser
			Dim bSuccess, sResult, sSpace

			sSpace = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"

			Set xmlParser = CreateObject("MSXML2.DOMDocument.6.0")
			xmlParser.Async = False
			bSuccess = xmlParser.Load("http://api.lunarstorm.se/api.ashx?gadget=true&type=rss&function=Live")

			If bSuccess Then
				Set xmlError = xmlParser.SelectSingleNode("error/item/description")

				If Not xmlError Is Nothing then
					sResult = "Error: " & xmlError.Text & " (will keep trying)"
				Else
					Set xlmNodes = xmlParser.SelectNodes("/rss/channel/item")
					sResult = sSpace

					For Each xlmNode In xlmNodes
						Set descNode = xlmNode.SelectSingleNode("description")
						Set linkNode = xlmNode.SelectSingleNode("link")
						Set publNode = xlmNode.SelectSingleNode("pubDate")
						Set titlNode = xlmNode.SelectSingleNode("title")
					
						If Not descNode Is Nothing And Not linkNode Is Nothing And Not publNode Is Nothing And Not titlNode Is Nothing Then
							sText = descNode.Text
							sLink = linkNode.Text
							sDate = publNode.Text
							sUser = titlNode.Text
	
					 		sResult = sResult & "<a href=""" & sLink & """ class=""tickerLink"">" & sUser & ": " & sText & "</a>" & sSpace
				 		End If
				 		
				 		Set descNode = Nothing
						Set linkNode = Nothing
						Set publNode = Nothing
						Set titlNode = Nothing
					Next
				End If

				Set xmlError = Nothing
				Set xlmNode = Nothing
				Set xlmNodes = Nothing
			End If

			Set xmlParser = Nothing
			Set xmlHttp = Nothing

			theTicker.InnerHTML = sResult
		End Sub
	</script>

	<script type="text/javascript" language="javascript">
		function settingsClosed() {
		  //code to update your gadget
		  Window_Onload();
		}
		
		function initGadget()
		{
			System.Gadget.settingsUI = "settings.htm";
			System.Gadget.onSettingsClosed = settingsClosed;

			checkState();
			System.Gadget.onDock = checkState;
			System.Gadget.onUndock = checkState;
		}

		function checkState()
		{
			if(!System.Gadget.docked)
			{
				undockedState();
			}
			else if (System.Gadget.docked)
			{
				dockedState();
			}
		}

		function undockedState()
		{
			//-- Resize body
			document.body.style.width = 730;
			System.Gadget.background = "_gfx/bg_large_name.png";

			//-- Resize elements
			document.getElementById("tickerArea").style.width = 730;
			document.getElementById("iconArea").style.top = 3;
			document.getElementById("iconArea").style.width = 166;
			document.getElementById("iconArea").style.height = 28;
			document.getElementById("gbIcon").style.width = 28;
			document.getElementById("lmIcon").style.width = 28;
			document.getElementById("fmIcon").style.width = 28;
			document.getElementById("frIcon").style.width = 28;
			document.getElementById("cmIcon").style.width = 28;

			//-- Show extra stuff
			document.getElementById("extrasArea").style.visibility = "visible";
		}

		function dockedState()
		{
			//-- Resize body
			document.body.style.width=130;
			System.Gadget.background = "_gfx/bg_small_name.png";

			//-- Resize elements
			document.getElementById("tickerArea").style.width = 130;
			document.getElementById("iconArea").style.top = 8;
			document.getElementById("iconArea").style.width = 130;
			document.getElementById("iconArea").style.height = 22;
			document.getElementById("gbIcon").style.width = 22;
			document.getElementById("lmIcon").style.width = 22;
			document.getElementById("fmIcon").style.width = 22;
			document.getElementById("frIcon").style.width = 22;
			document.getElementById("cmIcon").style.width = 22;

			//-- Hide extra stuff
			document.getElementById("extrasArea").style.visibility = "hidden";
		}

		function resetSearch()
		{
			document.getElementById("searchBox").value = 'Sök...';
		}
		function clearSearch()
		{
			document.getElementById("searchBox").value = '';
		}
		
		function showTooltip(obj)
		{
			if (System.Gadget.docked)
			{
				if (obj.value.length > 0)
				{
					var re = new RegExp("\\d+");
				  var m = re.exec(obj.value);
				  if (m != null)
				  {
				    tooltip(m[0]);
				  }
				}
			}
			else
			{
				if (obj.value.length > 0) { tooltip(obj.value); }
			}
		}
	</script>

	<body onload="initGadget()">
		<div id="iconArea" class="iconArea">
			<span class="Tooltip" id="gbTooltip" value="" onmouseover="showTooltip(this)" onmouseout="exit()">
				<a id="gbLink" href="http://www.lunarstorm.se/main.aspx?requestedUrl=http%3A%2F%2Fwww.lunarstorm.se%2Fgst%2Fgst_guestbook.aspx">
					<img src="_gfx/icon/icon-guestbook.gif" id="gbIcon" class="topIcon" alt="" />
				</a>
			</span>
			<span class="Tooltip" id="lmTooltip" value="" onmouseover="showTooltip(this)" onmouseout="exit()">
				<a id="lmLink" href="http://www.lunarstorm.se/main.aspx?requestedUrl=http%3A%2F%2Fwww.lunarstorm.se%2Fmai%2Fmai_mailbox.aspx">
					<img src="_gfx/icon/icon-lunarmail.gif" id="lmIcon" class="topIcon" alt="" />
				</a>
			</span>
			<span class="Tooltip" id="fmTooltip" value="" onmouseover="showTooltip(this)" onmouseout="exit()">
				<a id="fmLink" href="http://www.lunarstorm.se/main.aspx?requestedUrl=http%3A%2F%2Fwww.lunarstorm.se%2Fdis%2Fdis_forums.aspx">
					<img src="_gfx/icon/icon-forum.gif" id="fmIcon" class="topIcon" alt="" />
				</a>
			</span>
			<span class="Tooltip" id="frTooltip" value="" onmouseover="showTooltip(this)" onmouseout="exit()">
				<a id="frLink" href="http://www.lunarstorm.se/main.aspx?requestedUrl=http%3A%2F%2Fwww.lunarstorm.se%2Ffri%2Ffri_friends.aspx">
					<img src="_gfx/icon/icon-friends.gif" id="frIcon" class="topIcon" alt="" />
				</a>
			</span>
			<span class="Tooltip" id="cmTooltip" value="" onmouseover="showTooltip(this)" onmouseout="exit()">
				<a id="cmLink" href="javascript:void(0);">
					<img src="_gfx/icon/icon-comment.gif" id="cmIcon" class="topIcon" alt="" />
				</a>
			</span>
		</div>

		<div id="extrasArea" class="extrasArea"  style="visibility:hidden;">
			<div id="onlineArea" class="onlineArea">Updating...</div>
			<div id="searchArea" class="searchArea">
				<form method="get" action="http://www.lunarstorm.se/src/src_quicksearch.aspx">
					<div id="searchBoxBorder"></div><div id="searchBoxHolder"></div><input type="text" id="searchBox" name="all" value="Sök..." onfocus="clearSearch()" onblur="resetSearch()"/>
				</form>
			</div>
			<div id="logoArea" class="logoArea"><a href="http://www.lunarstorm.se/"><img src="_gfx/logo.png" style="vertical-align: middle;" border=0></a></div>
		</div>

		<div id="tickerArea" class="tickerArea">
			<marquee scrollamount="4" width="100%" id="theTicker" class="ticker" onMouseOver="theTicker.stop()" onMouseOut="theTicker.start()">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</marquee>
		</div>
		
		<div id="infoArea" />
		
		<div id="Debug" class="Debug" style="visibility:hidden;" />
	</body>
</html>